import {useNavigate} from "react-router-dom";
import {useEffect, useState} from "react";
import {message} from "antd";
import {getProfessionalCategoryInfoAPI, getProfessionalCategoryListAPI} from "@/apis/professionalCategory.jsx";


const useGetProfessionalCategoryById = (id) => {
    const navigator = useNavigate();
    const [professionalCategory, setProfessionalCategory] = useState({});
    useEffect(() => {
        const getOneProfessionalCategoryById = async () => {
            const res = await getProfessionalCategoryInfoAPI(id);
            if (res.code === 200) {
                setProfessionalCategory(res.data);
            }
            else if (res.code === 500) {
                message.error(res.msg);
                navigator('/backgroundManage/professionalCategory')
            }
        }
        getOneProfessionalCategoryById().then()
    }, [])
    return professionalCategory;
}


const useGetProfessionalList=(cur,pageSize)=>{
    const [professionalList,setProfessionalList] = useState([]);
    useEffect(() => {
        const getProfessionalList = async () => {
            const res=await getProfessionalCategoryListAPI(cur,pageSize);
            if (res.code === 200) {
                setProfessionalList(res.data);
            }
        }
        getProfessionalList().then();
    },[])
    return professionalList;
}


export {
    useGetProfessionalCategoryById,useGetProfessionalList
}